package com.das.mechanic_base.mvp.presenter.create;

import com.das.mechanic_base.base.X3BasePresenter;
import com.das.mechanic_base.bean.main.HomeBodyItemBean;
import com.das.mechanic_base.bean.main.ReceiveStatusBean;
import com.das.mechanic_base.mapi.api.NetWorkHttp;
import com.das.mechanic_base.mapi.response.HttpCallBack;
import com.das.mechanic_base.mapi.schedulers.RxSchedulersHelper;
import com.das.mechanic_base.mvp.contract.create.X3ServiceListContract;
import com.das.mechanic_base.utils.X3StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class X3ServiceListPresenter extends X3BasePresenter<X3ServiceListContract.View> implements X3ServiceListContract.Presenter {

    @Override
    public void requestReceiveStatus(int showIndex) {
        NetWorkHttp.getApi().getRecevieBaseStatusList()
                .compose(RxSchedulersHelper.defaultComposeRequest())
                .compose(mView.bindToLife())
                .subscribe(new HttpCallBack<List<ReceiveStatusBean>>() {
                    @Override
                    protected void onDone(List<ReceiveStatusBean> receiveStatusBeans) {
                        mView.getReceiveStatusSuccess(receiveStatusBeans,showIndex);
                    }

                    @Override
                    protected String LoadingMessage() {
                        return null;
                    }

                    @Override
                    protected void showError(String error) {

                    }
                });
    }

    @Override
    public void requestReceiveDetailList(Map<String, Object> map, long receiveBaseStatusId) {
        NetWorkHttp.getApi().getReceiveStatusDetailList(map,receiveBaseStatusId)
                .compose(RxSchedulersHelper.defaultComposeRequest())
                .compose(mView.bindToLife())
                .subscribe(new HttpCallBack<HomeBodyItemBean>() {
                    @Override
                    protected void onDone(HomeBodyItemBean itemBean) {
                        if (itemBean == null) {
                            mView.getReceiveDetailListSuccess(new ArrayList<>());
                            return;
                        }
                        List<HomeBodyItemBean.ListBean> list = itemBean.list;
                        if (X3StringUtils.isListEmpty(list)) {
                            list = new ArrayList<>();
                        }
                        mView.getReceiveDetailListSuccess(list);
                    }

                    @Override
                    protected String LoadingMessage() {
                        return null;
                    }

                    @Override
                    protected void showError(String error) {

                    }
                });
    }
}
